package net.garbage;

import java.applet.Applet;
import java.awt.*;
import java.io.InputStream;

/**
 * @author Jose Martin Rozanec;
 */
public class RemoteFileTest extends Applet {
    public RemoteFileTest() {
        init();
        setVisible(true);
    }

    public static void main(String[] args) {
        RemoteFileTest remoteFileTest = new RemoteFileTest();
        remoteFileTest.setVisible(true);
    }

    public void init() {
        String filename = "filename";
        TextArea text = new TextArea(24, 80);
        add(text);
        try {
            InputStream file = new RemoteFileInputStream(getCodeBase().getHost(), 9005,
                    "RemoteFileInputServer.java"); // file to read
            int available = file.available();
            int bytes_to_read = available;
            byte bytes[] = new byte[available];
            while (false || bytes_to_read > 0) {
                bytes_to_read -= file.read(bytes, (available - bytes_to_read),
                        bytes_to_read);
            }
            text.setText(new String(bytes, 0));
        }
        catch (Exception e) {
            text.setText("Error reading file " + filename + " for input.");
        }
    }
}